#!/bin/sh

#  Copyright (C) 2013 Curt Brune <curt@cumulusnetworks.com>
#
#  SPDX-License-Identifier:     GPL-2.0

# Extract tarball into specified directory

BUILD_DIR="$1"
TARBALL="$2"

usage() {
    cat <<EOF
$0: Usage
$0 <package build dir> <tarball>

Extract the <tarball> into the specified <build directory>.
EOF
}

[ -n "$BUILD_DIR" ] || {
    echo "Error: Build directory not specified"
    usage
    exit 1
}

[ -n "$TARBALL" ] || {
    echo "Error: tarball path not specified"
    usage
    exit 1
}

[ -r "$TARBALL" ] || {
    echo "Error: tarball does not exist: $TARBALL"
    usage
    exit 1
}

set -e

rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" && tar xf "$TARBALL"
